package com.day0922.weather;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import sun.net.www.http.HttpClient;

import java.io.Closeable;
import java.io.IOException;

public class Text {
    //获取天气预报
//    用Java代码获取天气预报
//    通过接口提供信息
//    接口 url
//    通过访问url 获得json字符串
//    用代码  模拟浏览器 发送请求
//    项目A  调用 项目B
    public static void main(String[] args) throws IOException {
        String str = "http://apis.juhe.cn/simpleWeather/query";
        // 1.创建httpclient
        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
        //2. 创建HttpGet
        HttpGet httpGet = new HttpGet(str);
        // 3. 请求执行，获取响应
        CloseableHttpResponse response = closeableHttpClient.execute(httpGet);
        System.out.println(response);
        // 4.获取响应实体
        HttpEntity httpEntity = response.getEntity();
        System.out.println(EntityUtils.toString(httpEntity,"UTF-8"));
        response.close();
        closeableHttpClient.close();

    }

}
